/**
 * 
 */
package edu.cmu.cs211.seamcarving.tests;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import edu.cmu.cs211.seamcarving.GradientFilter;
import edu.cmu.cs211.seamcarving.GrayImage;


public class GradientFilterTest {
  protected GradientFilter filter_;

  /**
   * @throws java.lang.Exception
   */
  @Before
  public void setUp() throws Exception {
    filter_ = new GradientFilter();
  }

  @Test
  public void squareImageTest() {
    // Use a 3x3 image to test the nominal case
    float[][] inputVals = { { 1.0f, 2.0f, 3.0f }, { 6.0f, 4.0f, 2.0f },
        { 6.0f, 8.0f, 0.0f } };
    float[][] expectedSqDiff = { { 26.0f, 5.0f, 10.0f }, { 4.0f, 20.0f, 8.0f },
        { 40.0f, 128.0f, 0.0f } };

    GrayImage filtered = filter_.filter(new GrayImage(inputVals));
    assertEquals(filtered.getHeight(), 3);
    assertEquals(filtered.getWidth(), 3);
    
    for (int row = 0; row < 3; ++row) {
      for (int col = 0; col < 3; ++col) {
        assertEquals("Unexpected entry at (" + row + "," + col + "): ",
            filtered.get(row, col), Math.sqrt(expectedSqDiff[row][col]), 1e-6);
      }
    }
  }
}
